﻿using System;
using System.Web.Security;
using Token.Piker.Common;

namespace Token.Piker.Web.Admin
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //注册
        protected void btnReg_Click(object sender, EventArgs e)
        {
            if (Session["ValidateCode"].ToString().ToUpper() != txtValidateCode.Text.Trim().ToUpper())
            {
                MessageBox.Show(this.Page, "验证码错误");
                return;
            }
            string AdminName = this.txtUserName.Text;
            string AdminPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "MD5");
            string RealName = this.txtRealName.Text;
            int Gender = 0;
            if (rdoFemale.Checked)
            {
                Gender = 1;
            }
            DateTime Birthday = DateTime.Parse(this.txtBirthday.Text);
            DateTime AddTime = DateTime.Now;
            string QQ = this.txtQQ.Text;
            string Email = this.txtEmail.Text;
            string Phone = this.txtPhone.Text;
            DateTime LastLogTime = DateTime.Now;
            string Authority = "000000";
            int Flag = 0;

            Token.Piker.Model.Admin model = new Token.Piker.Model.Admin();
            model.AdminName = AdminName;
            model.AdminPwd = AdminPwd;
            model.RealName = RealName;
            model.Gender = Gender;
            model.Birthday = Birthday;
            model.AddTime = AddTime;
            model.QQ = QQ;
            model.Email = Email;
            model.Phone = Phone;
            model.LastLogTime = LastLogTime;
            model.Authority = Authority;
            model.Flag = Flag;

            Token.Piker.BLL.AdminBLL bll = new Token.Piker.BLL.AdminBLL();

            try
            {
                bll.Add(model);
                MessageBox.Show(this, "注册成功，等待管理员审核！");
            }
            catch
            {
                MessageBox.Show(this, "注册失败,请稍后重试！");
            }
        }
    }
}